home *** CD-ROM | disk | FTP | other *** search
/ Varios Español / Varios Español.iso / DBASE5 / CUA_SAMP.ZIP / LOOKCOPY.PRG < prev    next >
Text File  |  1994-10-12  |  5KB  |  115 lines

  1. PROCEDURE LookCopy
  2. PARAMETERS poThis
  3. *----------------------------------------------------------------------------
  4. * NAME
  5. *   LookCopy - Copy the field values from the lookup table that match
  6. *              the field names in the main table.
  7. *
  8. *              The Lookup alias is currently in use.
  9. *
  10. *              Memo fields in the source file are ignored during the copy.
  11. *
  12. * PARAMETERS
  13. *   poThis     = oRef to the lookup field
  14. *
  15. *----------------------------------------------------------------------------
  16.     PRIVATE cTrigData, cTrigAlias, nFldCnt, nHits, i, nVoid, modTrigA, ;
  17.             oParrent, oFirst, oCurrent, nItem, cPostFrom
  18.  
  19.     cTrigData = poThis.DataLink
  20.     cTrigAlias = LEFT( m->cTrigData, AT( "->", m->cTrigData ) - 1 )
  21.  
  22.     *-------------------------------------------------------------
  23.     *-- Scan the fields in the Lookup alias for field name matches
  24.     *-- in the form.
  25.     *-------------------------------------------------------------
  26.     nFldCnt = AFIELDS( dB5___ALk )
  27.     DECLARE dB5___AMt[ m->nFldCnt ]
  28.     nHits = 0
  29.     FOR i = 1 TO m->nFldCnt
  30.  
  31.         *--------------------------------------------------------------
  32.         *-- Make up a field name that could be in the master file using
  33.         *-- the field from the lookup table.
  34.         *--------------------------------------------------------------
  35.         tryField = m->cTrigAlias + "->" + dB5___ALk[ m->i, 1 ]
  36.  
  37.         *-------------------------------------------------------------
  38.         *-- If this field exists and the types match, add the field to
  39.         *-- the array for scanning later.
  40.         *-------------------------------------------------------------
  41.         IF TYPE( m->tryField ) = dB5___ALk[ m->i, 2 ]
  42.             nHits = m->nHits + 1
  43.             dB5___AMt[ m->nHits ] = m->tryField
  44.         ENDIF
  45.  
  46.     ENDFOR
  47.  
  48.     *----------------------------------------
  49.     *-- Did any fields match names and types?
  50.     *----------------------------------------
  51.     IF m->nHits > 0
  52.  
  53.         modTrigA = m->cTrigAlias + "->" && Lookup field alias prefix
  54.  
  55.         *-------------------------------------------------------------
  56.         *-- Resize the matching field array to the number that matched
  57.         *-------------------------------------------------------------
  58.         nVoid = ARESIZE( dB5___AMt, m->nHits )
  59.  
  60.         *----------------------------------------------------------
  61.         *-- Now scan each object with an datalink against the array
  62.         *----------------------------------------------------------
  63.         oParent = poThis.Parent         && Get an oRef to this form
  64.         oFirst = oParent.First          && Get an oRef to the first object
  65.         oCurrent = m->oFirst            && Set the start object before loop
  66.         DO WHILE .T.
  67.  
  68.             *------------------------------------------------------------
  69.             *-- If this object has a datalink and the datalink matchs the
  70.             *-- the trigger field alias, then
  71.             *------------------------------------------------------------
  72.             IF TYPE( "oCurrent.DataLink" ) = "C" .AND. ;
  73.                 AT( modTrigA, UPPER( oCurrent.DataLink ) ) = 1
  74.  
  75.                 *-------------------------------------------------
  76.                 *-- Search the matching field array for this field
  77.                 *-------------------------------------------------
  78.                 nItem = ASCAN( dB5___AMt, UPPER( oCurrent.DataLink ) )
  79.  
  80.                 IF m->nItem > 0         && A match!
  81.  
  82.                     *---------------------------------------------------
  83.                     *-- Reconstruct the lookup field name before posting
  84.                     *---------------------------------------------------
  85.                     cPostFrom = poThis.LookAlias + "->" + ;
  86.                                 SUBSTR( dB5___AMt[ m->nItem ], ;
  87.                                         AT( "->", dB5___AMt[ m->nItem ] )+2 )
  88.  
  89.                     *------------------------------------------------
  90.                     *-- Post the corresponding value to the main file
  91.                     *------------------------------------------------
  92.                     IF .NOT. TYPE( m->cPostFrom ) $ "M,G"
  93.                         oCurrent.Value = EVALUATE( m->cPostFrom )
  94.                     ENDIF
  95.                 ENDIF
  96.             ENDIF
  97.  
  98.             *------------------------------------------------------------
  99.             *-- Get the next object on the form.  If it matches the first
  100.             *-- object, we are done.
  101.             *------------------------------------------------------------
  102.             oCurrent = oCurrent.After
  103.             IF oCurrent = m->oFirst
  104.                 EXIT
  105.             ENDIF
  106.         ENDDO
  107.     ENDIF
  108.  
  109.     RELEASE dB5___AMt, dB5___ALk
  110.  
  111. RETURN
  112. *-- EOP: LookCopy WITH poThis
  113.  
  114.  
  115.